//
// Created by jinxin on 2021-06-10.
//

#ifndef WEASEL_SERVER_H
#define WEASEL_SERVER_H
#include <sys/epoll.h>
#include "http/manage.h"

class server
{
public:
    explicit server(unsigned short port);

    //初始化服务,创建socket描述符并进行监听
    bool init();

    //反初始化,用于清理服务内的一些资源
    bool uninit();

    //获取socket描述符
    int get_socket();

    //初始化epoll
    bool init_epoll();

    //处理epoll消息
    void proc_epoll(int timeout);

private:
    //创建socket并监听
    int create_socket(unsigned short port);
    //设置socket为非阻塞
    int set_socket_non_blocking(int fd);
    //创建epoll
    int create_epoll();

private:
    int m_port;
    int m_sock;
    int m_epoll_fd;
    struct epoll_event m_ev;
    http_manage *m_p_http_manage;
};

#endif //WEASEL_SERVER_H
